package com.hades.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ContextServlet2 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 更简单的获取servlet的方法
        ServletContext context = getServletContext();
        context.setAttribute("key1","value1");
        Object key1 = context.getAttribute("key1");
        System.out.println("ContextServlet2中key1的值为" + key1);
    }
}
